package com.xiaoma.thread.Callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @author xiaomacdut
 * @date 2020年3月24日 上午10:29:07
 */
public class Main{
    
    public static void main(String [] args) throws InterruptedException, ExecutionException{
        // 第一种方式
        ExecutorService executor = Executors.newCachedThreadPool();
        Task task = new Task();
        FutureTask<Integer> futureTask = new FutureTask<Integer>(task);
        executor.submit(futureTask);
        executor.shutdown();
        try{
            Thread.sleep(1000);
        }catch(InterruptedException e1){
            e1.printStackTrace();
        }
        
        System.out.println("主线程在执行任务");
        
        try{
            System.out.println("task运行结果" + futureTask.get());
        }catch(InterruptedException e){
            e.printStackTrace();
        }catch(ExecutionException e){
            e.printStackTrace();
        }
        
        System.out.println("所有任务执行完毕");
    }
    
}
